﻿// VS defaults
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// specific to our add-in
using System.Runtime.InteropServices;
using Extensibility;
using Microsoft.Office.Interop.OneNote;
using Microsoft.Office.Core;
// for the ribbon icon images
using System.Runtime.InteropServices.ComTypes;
using System.Drawing.Imaging;
using System.IO;

namespace Norbauer.Office.OneNote.Addins.Commonplacing
{
    [GuidAttribute("27E68F0A-1B69-4e75-BABD-4D56E4B10D58"), ProgId("Norbauer.Office.OneNote.Commonplacing.AddIn")]
    public class AddIn : IDTExtensibility2, IRibbonExtensibility
    {
        ApplicationClass oneNoteApp = new ApplicationClass();

        #region IDTExtensibility2 Members
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
        {
            oneNoteApp = (ApplicationClass)application;
        }

        public void OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)
        {
            oneNoteApp = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        public void OnBeginShutdown(ref Array custom)
        {
            if (oneNoteApp != null)
                oneNoteApp = null;
        }

        public void OnAddInsUpdate(ref Array custom) { }
        
        public void OnStartupComplete(ref Array custom) { }
        #endregion

        #region IRibbonExtensibility Members
        public string GetCustomUI(string RibbonID)
        {
            return Properties.Resources.ribbon;
        }

        // called by the ribbon to fetch icons for the method buttons
        public IStream GetImages(string imageName)
        {
            MemoryStream mem = new MemoryStream();

            switch (imageName)
            {
                case "link_add.png":
                    Properties.Resources.link_add.Save(mem, ImageFormat.Png);
                    break;

                case "page_white_text.png":
                    Properties.Resources.page_white_text.Save(mem, ImageFormat.Png);
                    break;

                case "picture_go.png":
                    Properties.Resources.picture_go.Save(mem, ImageFormat.Png);
                    break;

                default:
                    return null;
            }

            return new CCOMStreamWrapper(mem);
        }

        #region methods called from Ribbon button press
        public void standardizeFormattingOfCurrentPage(IRibbonControl control)
        {
            Norbauer.Office.OneNote.Addins.Commonplacing.Tools.standardizeFormattingOfCurrentPage();
        }

        public void addLinkToCurrentPageToCurrentClipboardText(IRibbonControl control)
        {
            Norbauer.Office.OneNote.Addins.Commonplacing.Tools.addLinkToCurrentPageToCurrentClipboardText();
        }

        public void copyCleanedUpTextOfCurrentlySelectedOCRImageToClipboard(IRibbonControl control)
        {
            Norbauer.Office.OneNote.Addins.Commonplacing.Tools.copyCleanedUpTextOfCurrentlySelectedOCRImageToClipboard();
        }
        #endregion

        #endregion
    }

}




